//main.cpp
/********************************************************************************
*																				*
*	Author:			Jared Szechy												*
*	Assignment:		Assignment 6												*
*	Class:			CPS-151														*
*	Instructor:		V. Starkley													*
*	Due Date:		October 13													*
*																				*
*	This program dertermines if a phrase is a palindrome.						*
*																				*
********************************************************************************/
#include <iostream>
#include <string>
using namespace std;

#include "stack.h"
#include "Queue1.h"

void fillStackQueue(Stack<char>& theStack, QueType<char>& theQ, string phrase, int& length);
//pre: none
//post: fill the stack and queue with the entered phrase

bool checkPalindrome(Stack<char> theStack, QueType<char>& theQ, int length);
//pre: none
//post: returns true if the phrase is a palindrome

main()
{
	Stack<char> theStack;
	QueType<char> theQ;
	string phrase;
	int phraseLength;
	bool palindrome;

	cout << "Enter a word or phrase: ";
	while(isspace(cin.peek()))
		cin.ignore();
	getline(cin, phrase);

	phraseLength = phrase.length();

	fillStackQueue(theStack, theQ, phrase, phraseLength);

	palindrome = checkPalindrome(theStack, theQ, phraseLength);

	if(palindrome)
		cout << "The phrase: " << phrase << endl << "Is a palindrome" << endl;
	else
		cout << "The phrase: " << phrase << endl << "Is not a palindrome" << endl;

	system("pause");
	return 0;
}

void fillStackQueue(Stack<char>& theStack, QueType<char>& theQ, string phrase, int& length)
{
	int newLength = 0;
	for (int i = 0; i < length; i++)
	{
		if (isalpha(phrase[i]))
		{
			theStack.Push(phrase[i]);
			theQ.Enqueue(phrase[i]);
			newLength++;
		}
	}
	length = newLength;
}

bool checkPalindrome(Stack<char> theStack, QueType<char>& theQ, int length)
{
	char fromStack, fromQueue;

	for (int i = 0; i < length; i++)
	{
		theStack.Pop(fromStack);
		theQ.Dequeue(fromQueue);
		if(fromStack != fromQueue)
			return false;
	}
	return true;
}